﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：YS_JX_GUANLIK实体层次
//********************************************************************************//

#region Entity

using System;
using System.Data;
using Entity;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class YS_JX_GUANLIK
    {
        private decimal? m_dec_i_beiyong3;

        private decimal? m_dec_i_beiyong4;

        private decimal? m_dec_i_jlzt;

        private decimal? m_dec_i_leixing;

        private decimal m_dec_id;

        private DateTime? m_DT_d_caozuosj;

        private string m_str_s_beiyong1;

        private string m_str_s_beiyong2;

        private string m_str_s_caozuor;

        private string m_str_s_guanlikh;

        private string m_str_s_guanlikmc;

        private string m_str_s_zhandian;

        /// <summary>
        ///     自增量
        /// </summary>
        public decimal ID
        {
            get { return m_dec_id; }
            set { m_dec_id = value; }
        }

        /// <summary>
        ///     管理块号
        /// </summary>
        public string S_GUANLIKH
        {
            get { return m_str_s_guanlikh; }
            set { m_str_s_guanlikh = value; }
        }

        /// <summary>
        ///     管理块名称
        /// </summary>
        public string S_GUANLIKMC
        {
            get { return m_str_s_guanlikmc; }
            set { m_str_s_guanlikmc = value; }
        }

        /// <summary>
        ///     站点编号
        /// </summary>
        public string S_ZHANDIAN
        {
            get { return m_str_s_zhandian; }
            set { m_str_s_zhandian = value; }
        }

        /// <summary>
        ///     管理块类型(0:所有区块;1:管理和考核统一区域;2:其他考核用户)
        /// </summary>
        public decimal? I_LEIXING
        {
            get { return m_dec_i_leixing; }
            set { m_dec_i_leixing = value; }
        }

        /// <summary>
        ///     备用1
        /// </summary>
        public string S_BEIYONG1
        {
            get { return m_str_s_beiyong1; }
            set { m_str_s_beiyong1 = value; }
        }

        /// <summary>
        ///     备用2
        /// </summary>
        public string S_BEIYONG2
        {
            get { return m_str_s_beiyong2; }
            set { m_str_s_beiyong2 = value; }
        }

        /// <summary>
        ///     记录状态(0:正常;-1:逻辑删除)
        /// </summary>
        public decimal? I_JLZT
        {
            get { return m_dec_i_jlzt; }
            set { m_dec_i_jlzt = value; }
        }

        /// <summary>
        ///     操作人
        /// </summary>
        public string S_CAOZUOR
        {
            get { return m_str_s_caozuor; }
            set { m_str_s_caozuor = value; }
        }

        /// <summary>
        ///     操作时间
        /// </summary>
        public DateTime? D_CAOZUOSJ
        {
            get { return m_DT_d_caozuosj; }
            set { m_DT_d_caozuosj = value; }
        }

        /// <summary>
        ///     备用3
        /// </summary>
        public decimal? I_BEIYONG3
        {
            get { return m_dec_i_beiyong3; }
            set { m_dec_i_beiyong3 = value; }
        }

        /// <summary>
        ///     备用4
        /// </summary>
        public decimal? I_BEIYONG4
        {
            get { return m_dec_i_beiyong4; }
            set { m_dec_i_beiyong4 = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL.Access
{
    //using System.Data.OracleClient;

    public class YS_JX_GUANLIKProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public YS_JX_GUANLIKProcess()
        {
            conn = ConfigHelper.PlatformConnString;
        }

        #endregion

        #region public

        /// <summary>
        ///     根据YS_JX_GUANLIK实体添加或者修改YS_JX_GUANLIK信息
        /// </summary>
        public bool InsertOrUpdate(YS_JX_GUANLIK YS_JX_GUANLIK, OracleTransaction Transaction)
        {
            if (YS_JX_GUANLIK.ID == 0)
                InsertYS_JX_GUANLIK(YS_JX_GUANLIK, Transaction);
            else
                UpdateYS_JX_GUANLIK(YS_JX_GUANLIK, Transaction);
            return YS_JX_GUANLIK.ID == 0 ? false : true;
        }

        /// <summary>
        ///     根据YS_JX_GUANLIK实体添加或修改YS_JX_GUANLIK信息
        /// </summary>
        public bool InsertOrUpdate(YS_JX_GUANLIK YS_JX_GUANLIK)
        {
            return InsertOrUpdate(YS_JX_GUANLIK, null);
        }


        /// <summary>
        ///     根据YS_JX_GUANLIK主键删除YS_JX_GUANLIK信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteYS_JX_GUANLIK(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_DelYS_JX_GUANLIK";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据YS_JX_GUANLIK主键删除YS_JX_GUANLIK信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteYS_JX_GUANLIK(decimal ID)
        {
            return DeleteYS_JX_GUANLIK(ID, null);
        }

        /// <summary>
        ///     根据条件删除YS_JX_GUANLIK信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteYS_JX_GUANLIKsDynamic(string WhereClause, OracleTransaction Transaction)
        {
            var spName = "CS_DelYS_JX_GUANLIKsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据条件删除YS_JX_GUANLIK信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteYS_JX_GUANLIKsDynamic(string WhereClause)
        {
            return DeleteYS_JX_GUANLIKsDynamic(WhereClause, null);
        }

        /// <summary>
        ///     根据YS_JX_GUANLIK主键选择YS_JX_GUANLIK信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_JX_GUANLIK信息</returns>
        public YS_JX_GUANLIK SelectYS_JX_GUANLIK(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_JX_GUANLIK";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                var YS_JX_GUANLIK = PopulateYS_JX_GUANLIK(rd);
                rd.Close();
                return YS_JX_GUANLIK;
            }
            return null;
        }

        /// <summary>
        ///     根据YS_JX_GUANLIK主键选择YS_JX_GUANLIK信息
        /// </summary>
        /// <returns>YS_JX_GUANLIK信息</returns>
        public YS_JX_GUANLIK SelectYS_JX_GUANLIK(decimal ID)
        {
            return SelectYS_JX_GUANLIK(ID, null);
        }

        /// <summary>
        ///     选择所有YS_JX_GUANLIK信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有YS_JX_GUANLIK信息</returns>
        public DataTable SelectYS_JX_GUANLIKsAll(OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_JX_GUANLIKsAll";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }

        /// <summary>
        ///     选择所有YS_JX_GUANLIK信息
        /// </summary>
        /// <returns>所有YS_JX_GUANLIK信息</returns>
        public DataTable SelectYS_JX_GUANLIKsAll()
        {
            return SelectYS_JX_GUANLIKsAll(null);
        }

        /// <summary>
        ///     根据条件选择YS_JX_GUANLIK信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_JX_GUANLIK信息</returns>
        public DataTable SelectYS_JX_GUANLIKsDynamic(string WhereClause, string OrderByExpression,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_JX_GUANLIKsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择YS_JX_GUANLIK信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>YS_JX_GUANLIK信息</returns>
        public DataTable SelectYS_JX_GUANLIKsDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectYS_JX_GUANLIKsDynamic(WhereClause, OrderByExpression, null);
        }


        /// <summary>
        ///     根据条件选择YS_JX_GUANLIK信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_JX_GUANLIK信息</returns>
        public DataTable SelectYS_JX_GUANLIKsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize, OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_JX_GUANLIKsDynPaged";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择YS_JX_GUANLIK信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>YS_JX_GUANLIK信息</returns>
        public DataTable SelectYS_JX_GUANLIKsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize)
        {
            return SelectYS_JX_GUANLIKsDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///     根据条件更新YS_JX_GUANLIK字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateYS_JX_GUANLIKsDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            var result = 0;
            if (UpdateValue == "" || WhereClause == "")
                return 0;
            var spName = "CS_UpdYS_JX_GUANLIKDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///     根据条件更新YS_JX_GUANLIK字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateYS_JX_GUANLIKsDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateYS_JX_GUANLIKsDynamic(UpdateValue, WhereClause, null);
        }

        #endregion

        #region Private

        private int InsertYS_JX_GUANLIK(YS_JX_GUANLIK YS_JX_GUANLIK, OracleTransaction Transaction)
        {
            var spName = "CS_InsYS_JX_GUANLIK";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = YS_JX_GUANLIK.S_GUANLIKH;
            storedParams[1].Value = YS_JX_GUANLIK.S_GUANLIKMC;
            storedParams[2].Value = YS_JX_GUANLIK.S_ZHANDIAN;
            storedParams[3].Value = YS_JX_GUANLIK.I_LEIXING;
            storedParams[4].Value = YS_JX_GUANLIK.S_BEIYONG1;
            storedParams[5].Value = YS_JX_GUANLIK.S_BEIYONG2;
            storedParams[6].Value = YS_JX_GUANLIK.I_JLZT;
            storedParams[7].Value = YS_JX_GUANLIK.S_CAOZUOR;
            storedParams[8].Value = YS_JX_GUANLIK.D_CAOZUOSJ;
            storedParams[9].Value = YS_JX_GUANLIK.I_BEIYONG3;
            storedParams[10].Value = YS_JX_GUANLIK.I_BEIYONG4;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            YS_JX_GUANLIK.ID = Convert.ToInt32(storedParams[11].Value);
            return result;
        }

        private bool UpdateYS_JX_GUANLIK(YS_JX_GUANLIK YS_JX_GUANLIK, OracleTransaction Transaction)
        {
            var spName = "CS_UpdYS_JX_GUANLIK";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = YS_JX_GUANLIK.S_GUANLIKH;
            storedParams[1].Value = YS_JX_GUANLIK.S_GUANLIKMC;
            storedParams[2].Value = YS_JX_GUANLIK.S_ZHANDIAN;
            storedParams[3].Value = YS_JX_GUANLIK.I_LEIXING;
            storedParams[4].Value = YS_JX_GUANLIK.S_BEIYONG1;
            storedParams[5].Value = YS_JX_GUANLIK.S_BEIYONG2;
            storedParams[6].Value = YS_JX_GUANLIK.I_JLZT;
            storedParams[7].Value = YS_JX_GUANLIK.S_CAOZUOR;
            storedParams[8].Value = YS_JX_GUANLIK.D_CAOZUOSJ;
            storedParams[9].Value = YS_JX_GUANLIK.I_BEIYONG3;
            storedParams[10].Value = YS_JX_GUANLIK.I_BEIYONG4;
            storedParams[11].Value = YS_JX_GUANLIK.ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private YS_JX_GUANLIK PopulateYS_JX_GUANLIK(IDataReader dr)
        {
            var YS_JX_GUANLIK = new YS_JX_GUANLIK();
            YS_JX_GUANLIK.ID = dr["ID"] == DBNull.Value ? 0 : (decimal) dr["ID"];
            YS_JX_GUANLIK.S_GUANLIKH = dr["S_GUANLIKH"] == DBNull.Value ? null : (string) dr["S_GUANLIKH"];
            YS_JX_GUANLIK.S_GUANLIKMC = dr["S_GUANLIKMC"] == DBNull.Value ? null : (string) dr["S_GUANLIKMC"];
            YS_JX_GUANLIK.S_ZHANDIAN = dr["S_ZHANDIAN"] == DBNull.Value ? null : (string) dr["S_ZHANDIAN"];
            YS_JX_GUANLIK.I_LEIXING = dr["I_LEIXING"] == DBNull.Value ? null : (decimal?) dr["I_LEIXING"];
            YS_JX_GUANLIK.S_BEIYONG1 = dr["S_BEIYONG1"] == DBNull.Value ? null : (string) dr["S_BEIYONG1"];
            YS_JX_GUANLIK.S_BEIYONG2 = dr["S_BEIYONG2"] == DBNull.Value ? null : (string) dr["S_BEIYONG2"];
            YS_JX_GUANLIK.I_JLZT = dr["I_JLZT"] == DBNull.Value ? null : (decimal?) dr["I_JLZT"];
            YS_JX_GUANLIK.S_CAOZUOR = dr["S_CAOZUOR"] == DBNull.Value ? null : (string) dr["S_CAOZUOR"];
            YS_JX_GUANLIK.D_CAOZUOSJ = dr["D_CAOZUOSJ"] == DBNull.Value ? null : (DateTime?) dr["D_CAOZUOSJ"];
            YS_JX_GUANLIK.I_BEIYONG3 = dr["I_BEIYONG3"] == DBNull.Value ? null : (decimal?) dr["I_BEIYONG3"];
            YS_JX_GUANLIK.I_BEIYONG4 = dr["I_BEIYONG4"] == DBNull.Value ? null : (decimal?) dr["I_BEIYONG4"];
            return YS_JX_GUANLIK;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (var i = 0; i < dt.Rows.Count; i++)
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
        }

        #endregion
    }
}

#endregion